#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
# author: 小菠萝测试笔记
# blog:  https://www.cnblogs.com/poloyy/
# time: 2021/10/12 8:36 下午
# file: base_class.py
"""
import datetime

from sqlalchemy import Column, DateTime, Integer
from sqlalchemy.orm import as_declarative, declared_attr


@as_declarative()
class Base(object):
    __table_args__ = {"extend_existing": True}

    id = Column(Integer, primary_key=True, autoincrement=True, index=True)
    create_time = Column(
        DateTime, default=datetime.datetime.now(), comment="创建时间: 年月日 时分秒"
    )
    update_time = Column(
        DateTime,
        default=datetime.datetime.now(),
        onupdate=datetime.datetime.now(),
        comment="更新时间: 年月日 时分秒",
    )
    is_delete = Column(Integer, default=0, comment="是否被删除，1 已被删除，0 未删除")

    # __tablename__ 可自动生成
    @declared_attr
    def __tablename__(cls) -> str:
        return cls.__name__.lower()
